import * as Cesium from 'cesium';
import * as Libora from '../../public/libora/index.js'

(window).Cesium = Cesium;
(window).Libora = Libora;

let info = {};
info.lon = -95;
info.lat = 25;

export default class PrimitivePlane {
  constructor() {
    const viewer = Libora.getViewer({
      imageryProvider: false,
      globe: false,
    });
    viewer.camera.flyTo({
      destination: Cesium.Cartesian3.fromDegrees(info.lon, info.lat, 2000000.0),
      duration: 0,
    });

    const position = Cesium.Cartesian3.fromDegrees(info.lon, info.lat, 0)
    this.addPrimitivePlane(viewer,position);
  }

  addPrimitivePlane(viewer) {
    const geometry = new Cesium.RectangleGeometry({
      rectangle: Cesium.Rectangle.fromDegrees(-100.0, 20.0, -90.0, 30.0),
      vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
    });

    const instance = new Cesium.GeometryInstance({
      geometry: geometry
    });

    const primitive = new Cesium.Primitive({
      geometryInstances: instance,
      appearance: new Cesium.EllipsoidSurfaceAppearance({
        material: Cesium.Material.fromType('Stripe')
      })
    })
    viewer.scene.primitives.add(primitive);
  }
}
